package com.mall.service.impl;

import com.mall.common.utils.Security;
import com.mall.dao.custom.CtFavoriteMapper;
import com.mall.entity.Favorite;
import com.mall.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author xyl
 * @date 2021-03-02 14:51
 */
@Service
public class FavoriteServiceImpl implements FavoriteService {

    @Autowired
    private CtFavoriteMapper favoriteMapper;


    @Override
    public int add(Integer goodsId) {
        Favorite favorite = new Favorite();
        favorite.setCreateTime(new Date());
        favorite.setGoodsId(goodsId);
        favorite.setUserId(Security.getCurrentUserId());
        return favoriteMapper.insert(favorite);
    }

    @Override
    public int remove(Integer goodsId) {
        return favoriteMapper.deleteByGoodsIdAndUserId(goodsId,Security.getCurrentUserId());
    }

    @Override
    public Favorite getFavoriteByGoodsId(Integer goodsId) {
        return favoriteMapper.selectFavoriteByGoodsIdAndUserId(goodsId,Security.getCurrentUserId());
    }
}
